package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.BasicPhDilute;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.BasicPhDiluteService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 基础表——滴定pH——稀释 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-08-01
 */

@Api(tags = {"滴定pH-稀释 前端控制器"})
@RestController
@RequestMapping("/basic-ph-dilute")
public class BasicPhDiluteController {

    @Autowired
    BasicPhDiluteService basicPhDiluteService;

    /**
     * 滴定pH-稀释 新增项目
     * @param basicPhDilute 新数据
     * @return result code 0成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addBasicPhDilute(@RequestBody BasicPhDilute basicPhDilute){
        basicPhDilute.setId(RandomIdUtil.createRandomId());
        basicPhDiluteService.save(basicPhDilute);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, basicPhDilute);
    }

    /**
     * 滴定pH-稀释 查看（分页）
     * @param diluteNo 编号
     * @param current 分页 当前页
     * @param size 分页 每页数据量
     * @return 返回当页数据
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listBasicPhDilute(@RequestParam("diluteNo") String diluteNo, @RequestParam("current") Integer current,
                              @RequestParam("size") Integer size){
        IPage<BasicPhDilute> page = basicPhDiluteService.listPhDilute(diluteNo, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 滴定pH-稀释 根据id删除项目
     * @param id 需删除项目的id
     * @return result code 0成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteBasicPhDilute(@RequestParam("id") Long id){
        basicPhDiluteService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 滴定pH-稀释 更新项目
     * @param basicPhDilute 更新的项目
     * @return result code 0成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateBasicPhDilute(@RequestBody BasicPhDilute basicPhDilute){
        basicPhDiluteService.updateById(basicPhDilute);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

